<?php

namespace app\controller;

use Predis\Client;
use support\Cache;

class CounterController
{
    protected $redis;

    public function __construct()
    {
        $this->redis = new Client(); // 连接到 Redis
    }

    public function increment()
    {
        // 增加计数器
        $count = $this->redis->incr('auto_increment_counter');
        return json(['count' => $count]);
    }

    public function getCount()
    {
        // 获取当前计数器的值
        $count = $this->redis->get('increment_value');
        return json(['count' => $count ?: 0]);
    }

    public function getTreeCount()
    {
        return json(['tree_count = ' => Cache::get('world_tree')]);
    }
}